package com.codigosandroid.mobilegourmet.adapter;

import java.util.List;

import com.codigosandroid.mobilegourmet.R.id;
import com.codigosandroid.mobilegourmet.R.layout;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListAdapter extends BaseAdapter{

	private List<Integer> lstImage;
	private List<String> lstItem;
	private LayoutInflater inflater;
	private Context context;
	
	public ListAdapter(Context context, List<Integer> lstImage, List<String> lstItem){
		
		this.context = context;
		this.lstImage = lstImage;
		this.lstItem = lstItem;
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
	}
	
	@Override
	public int getCount() {
	
		return lstImage.size();
	
	}

	@Override
	public Object getItem(int position) {
		
		return lstImage.get(position);
	
	}

	@Override
	public long getItemId(int position) {
		
		return 0;
	
	}

	public static class ViewHolder{
		
		public ImageView imgView;
		public TextView txtView;
		
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		ViewHolder holder;
		
		if(convertView == null){
			
			convertView = inflater.inflate(layout.menu_outros_pedido_row, null);
			
			holder = new ViewHolder();
			holder.imgView = (ImageView) convertView.findViewById(id.img_icon_menu);
			holder.txtView = (TextView) convertView.findViewById(id.lbl_name_menu);
			
			convertView.setTag(holder);
			
		} else {
			
			holder = (ViewHolder) convertView.getTag();
			
		}
		
		holder.imgView.setImageResource(lstImage.get(position));
		holder.txtView.setText(lstItem.get(position));
		
		return convertView;
	}

}
